var t = getApp()
var iconsUrl = t.globalData.iconsUrl
Page({
  data: {
    iconsUrl:t.globalData.iconsUrl,
    item:'',
    navHeight:t.globalData.navHeight,
    title:'商品详情',
  },
  onLoad: function (options) {
    this.setData({
      item:JSON.parse(options.item)
    })
    console.log(this.data.item);
  },
  onRefresh(){
    //在当前页面显示导航条加载动画
    wx.showNavigationBarLoading(); 
    //显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框
  },
  onPullDownRefresh: function () {
    //调用刷新时将执行的方法
    this.onRefresh();
    setTimeout(function () {
      // 不加这个方法真机下拉会一直处于刷新状态，无法复位
      wx.stopPullDownRefresh()
    }, 1000)
  },
  back_index(e){
    wx.switchTab({
      url: '/pages/index/index',
    })
  },
  exchange(e){
    var that = this
    if (this.data.item.mail==0) {
      wx.showModal({
        title:'提示',
        content:'确认兑换' + that.data.item.title + '吗？',
        success(e){
          if (e.confirm) {
            t.request('/goods/buy',{good_id:that.data.item.id,addr_id:''},function(e){
              console.log(e);
              if(e.code==200){
                wx.showToast({
                  title: '兑换成功',
                })
              }else{
                wx.showToast({
                  title: e.msg,
                  icon:'none'
                })
              }
            })
          }else{

          }
        }
      })

    }else{
      wx.navigateTo({
        url: '/pages/personCenter/set/set_addr/set_addr?good_id=' + that.data.item.id,
      })
    }
  }
})